﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Atom.DAL;
using Atom.Entity;
using System.Data;
using System.Collections;
using Atom.Utility;

namespace Atom.BLL
{
    public class C3_1BLL : BaseBLL
    {
        public List<C3_1Entity> GenernateC3_1Entity(DateTime dtbegin, DateTime dtEnd, string sickName)
        {

            List<C3_1Entity> entitys = new List<C3_1Entity>();
            try
            {

                LeaveHosRecordDAL dal = new LeaveHosRecordDAL();
                List<BZEntity> bzEntitys = ReadXml.GetBZEntity();
                List<AgeEntity> ageEntitys = MedInfo.GetAgeEntity();
                List<MedTypeEntity> medtypeEntitys = MedInfo.GetMedTypeEntity();
                int temp = 0;

                //循环病种
                foreach (BZEntity bzentity in bzEntitys)
                {

                    //循环年龄段
                    foreach (AgeEntity item in ageEntitys)
                    {
                        //循环人群类别
                        foreach (MedTypeEntity medtypeentity in medtypeEntitys)
                        {


                            C3_1Entity entity = new C3_1Entity();

                            entity.BZType = bzentity.Index;
                            entity.CHRQAgeType = item.Code;
                            entity.CHRQType = medtypeentity.Index;
                            entity.BZName = bzentity.BZName;
                            entity.CHRQAgeName = item.Name;
                            entity.CHRQName = medtypeentity.Name;


                            //基本信息
                            DataSet dsRecord = dal.GetLeaveHosRecordByDateAge(dtbegin, dtEnd, item.AgeBegin, item.AgeEnd, bzentity.BZCode, medtypeentity.Code);
                            entity.OutHosCount = (dsRecord == null) ? 0 : (dsRecord.Tables[0].Rows.Count < 1) ? 0 : Convert.ToInt32(dsRecord.Tables[0].Rows[0]["REGISTERNO"]);
                            entity.OuthosBedCount = (dsRecord == null) ? 0 : (dsRecord.Tables[0].Rows.Count < 1) ? 0 : Convert.ToInt32(dsRecord.Tables[0].Rows[0]["INHOSDAYS"]);
                            entity.TotalFee = (dsRecord == null) ? 0 : (dsRecord.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsRecord.Tables[0].Rows[0]["TOTALCONSUMEMONEY"]);

                            //补偿范围总费用
                            entity.BCFWTotalFee = (dsRecord == null) ? 0 : (dsRecord.Tables[0].Rows.Count < 1) ? 0 : Convert.ToDecimal(dsRecord.Tables[0].Rows[0]["DISCOUNTPAY"]);

                            //   1.3.1 其中：药品总费用(元)
                            //          检查费用(元)
                            //         手术费用（元）      
                            //          治疗费用（元）   
                            DataSet dsTemp = new DataSet();
                            dsTemp = dal.GetLeaveHosRecordByDateAgeForItem(dtbegin, dtEnd, item.AgeBegin, item.AgeEnd, bzentity.BZCode, Constants.SUMMARY_YP, medtypeentity.Code);
                            entity.YPFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToInt32(dsTemp.Tables[0].Rows[0]["MONEY"]);

                            dsTemp = dal.GetLeaveHosRecordByDateAgeForItem(dtbegin, dtEnd, item.AgeBegin, item.AgeEnd, bzentity.BZCode, Constants.SUMMARY_JC, medtypeentity.Code);
                            entity.JCFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToInt32(dsTemp.Tables[0].Rows[0]["MONEY"]);

                            dsTemp = dal.GetLeaveHosRecordByDateAgeForItem(dtbegin, dtEnd, item.AgeBegin, item.AgeEnd, bzentity.BZCode, Constants.SUMMARY_SS, medtypeentity.Code);
                            entity.SSFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToInt32(dsTemp.Tables[0].Rows[0]["MONEY"]);

                            dsTemp = dal.GetLeaveHosRecordByDateAgeForItem(dtbegin, dtEnd, item.AgeBegin, item.AgeEnd, bzentity.BZCode, Constants.SUMMARY_ZL, medtypeentity.Code);
                            entity.ZLFee = (dsTemp == null) ? 0 : (dsTemp.Tables[0].Rows.Count < 1) ? 0 : Convert.ToInt32(dsTemp.Tables[0].Rows[0]["MONEY"]);


                            entitys.Add(entity);

                        }


                    }


                    temp++;

                }


                //SELECT  count(T3.REGISTERNO)REGISTERNO,SUM(T2.INHOSDAYS)INHOSDAYS,SUM(T1.TOTALCONSUMEMONEY)TOTALCONSUMEMONEY
            }
            catch (Exception ex)
            {
                log.Error("C31BLL-->" + ex.Message);

            }
            return entitys;




        }
    }
}
